﻿// HSS.ServiceModel.Internal.VirtualServiceCredentials.cs
// ----------------------------------------------------------------------------
// Licensed under the MIT license
// http://www.opensource.org/licenses/mit-license.html
// ----------------------------------------------------------------------------
// HighSpeed-Solutions, LLC
// Copyright (c) 2001-2010
// ----------------------------------------------------------------------------
// File:       VirtualServiceCredentials.cs
// Author:     HSS\gbanta
// Created:    08/12/2010
// Modified:   12/05/2010
// ----------------------------------------------------------------------------
namespace HSS.ServiceModel.Internal
{
	#region Using Directives
	using System.ServiceModel;
	using System.ServiceModel.Channels;
	#endregion

	#region VirtualServiceCredentials
	/// <summary>
	/// VirtualServiceCredentials
	/// </summary>
#if !DEBUG
	[System.Diagnostics.DebuggerStepThroughAttribute()]
#endif
	internal sealed class VirtualServiceCredentials : IMessageInspector
	{
		#region Constants
		private const string headerName = "VirtualServiceCredentials";
		private const string headerNamespace = "http://highspeed-solutions.net/ServiceModel/v100";
		#endregion

		#region Fields
		private string user;
		private string token;
		#endregion

		#region Constructors
		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="userName">The user name.</param>
		/// <param name="password">The password.</param>
		public VirtualServiceCredentials(string userName, string password)
		{
			this.user = userName;
			this.token = password;
		}
		#endregion

		public object BeforeSendRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel)
		{
			string sep = "\u2521";
			var x = this.user + sep + this.token;
			var b = System.Text.UTF8Encoding.UTF8.GetBytes(x);
			var s = System.Convert.ToBase64String(b);
			request.Headers.Add(MessageHeader.CreateHeader(headerName, headerNamespace, s));
			return null;
		}

		public void AfterReceiveReply(ref System.ServiceModel.Channels.Message reply, object correlationState)
		{
		}
	}
	#endregion
}